package arithmetic.string;

/**
 * 将字符串aaabbbbcc变成3a4b2c
 */
public class Transform {
    public static String transform(String s) {
        int n = s.length();
        int num = 1;
        char preWord = s.charAt(0);
        StringBuilder result = new StringBuilder();
        for (int i = 1; i < n; i++) {
            char currentWord = s.charAt(i);
            if (currentWord == preWord) {
                num++;
                continue;
            }
            result = result.append(num).append(preWord);
            preWord = currentWord;
            num = 1;
        }
        result = result.append(num).append(preWord);
        return result.toString();
    }

    public static void main(String[] args) {
        String a = "bbcccdd";
        String c = transform(a);
        System.out.println(c);
    }
}
